Imports System.Windows.Forms
Imports System.Configuration
Imports DAL
Imports MyClasses

Public Class MDINP
    Private ptStartPoint As New Point
    ''Private btnShortCuts() As Button      'Button Array used as buttons for Shortcuts 
    Private lblShortCuts() As Button       'Button Array used as buttons for Shortcuts 
    Private Const MdiFudge As Integer = 4 'fudge factor for 'ScaleWidth/ScaleHeight'
    Public MdiScaleHeight As Integer
    Public MdiScaleWidth As Integer
    Public SubFormLocation As New Point
    Private objItem() As CExpItem
    Public boolFinYr As Boolean


#Region "GET MDI SCALE HEIGHT WIDTH,LEFT,TOP"
    Private Sub SetMDISchaleValues()
        Call GetMdiScaleHeight()
        Call GetMdiScaleWidth()
        Call GetMDIScaleTop()
        Call GetMDIScaleLeft()
    End Sub

    Private Sub SetPanelHeading()
        Dim dblWidth As Integer = 0
        dblWidth = (pnlHeading.Width / 3)
        'lblDateTime.Size = New System.Drawing.Size(dblWidth + 10, 24)
        lblFirmName.Size = New System.Drawing.Size(dblWidth, 24)
        lblScreen.Size = New System.Drawing.Size(dblWidth, 24)

        lblFirmName.Location = New System.Drawing.Point(-1, -1)
        lblScreen.Location = New System.Drawing.Point((lblFirmName.Right) - 4, -1)
        'lblDateTime.Location = New System.Drawing.Point((lblScreen.Right) - 4, -1)
    End Sub

    Private Sub GetMdiScaleHeight()
        ' Consider docked controls in the mdi and if docked then reduce the size
        Dim ctl As Control
        Dim h As Long = Me.ClientSize.Height

        For Each ctl In Me.Controls
            With ctl
                If .GetContainerControl() Is Me Then   'docked to the mdi form
                    Debug.Print(ctl.Name)
                    If .Dock = DockStyle.Top Or .Dock = DockStyle.Bottom Then
                        If .Visible = True Then h = h - .Size.Height
                    End If
                End If
            End With
        Next
        MdiScaleHeight = h - MdiFudge
    End Sub

    Private Sub GetMdiScaleWidth()
        ' Consider docked controls in the mdi and if docked then reduce the size
        Dim ctl As Control
        Dim w As Integer = Me.ClientSize.Width

        For Each ctl In Me.Controls
            With ctl
                If .GetContainerControl() Is Me Then   'docked to the mdi form
                    If .Dock = DockStyle.Left Or .Dock = DockStyle.Right Then
                        If .Visible = True Then w = w - .Size.Width
                    End If
                End If
            End With
        Next
        MdiScaleWidth = w - MdiFudge
    End Sub

    Private Sub GetMDIScaleTop()
        ' Consider docked controls in the mdi and if docked then reduce the size
        Dim ctl As Control
        Dim h As Integer = 0
        For Each ctl In Me.Controls
            With ctl
                If .GetContainerControl() Is Me Then   'docked to the mdi form
                    Debug.Print(ctl.Name)
                    If .Dock = DockStyle.Top Then
                        If .Visible = True Then h = h + .Size.Height
                    End If
                End If
            End With
        Next
        SubFormLocation.Y = h - MdiFudge
    End Sub

    Private Sub GetMDIScaleLeft()
        ' Consider docked controls in the mdi and if docked then reduce the size
        Dim ctl As Control
        Dim w As Integer = 0

        For Each ctl In Me.Controls
            With ctl
                If .GetContainerControl() Is Me Then   'docked to the mdi form
                    If .Dock = DockStyle.Left Then
                        If .Visible = True Then w = w + .Size.Width
                    End If
                End If
            End With
        Next
        SubFormLocation.X = w - MdiFudge
    End Sub
#End Region

#Region "USER DEFINED FUNCTION"
    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            ''Dim FileName As String = OpenFileDialog.FileName
            ' TODO: ADD CODE HERE TO OPEN THE FILE.
        End If
    End Sub

    '@20/03/2008 : Added regarding assignment of Roles & Privilege
    Public Sub AssignPrivilege()
        Dim dtPriv As New DataTable
        Try

            'dtPriv = DRole.GetRolePriv(ConfigurationManager.AppSettings("UserID"))
            'If dtPriv.Rows.Count > 0 Then
            '    For intCount = 0 To dtPriv.Rows.Count - 1
            '        Select Case dtPriv.Rows(intCount).Item("PrID")
            '            Case 3
            '                Me.BackupToolStripMenuItem.Enabled = True               'Backup
            '            Case 4
            '                Me.MnuRestoreDb.Enabled = True                          'Restore
            '            Case 5
            '                Me.ReporToolStripMenuItem.Enabled = True                'Reports
            '            Case 6
            '                Me.mnuBnkMrgnStatement.Enabled = True                   'Correction Statement
            '            Case 8
            '                Me.mnuOpeningStock.Enabled = True                       'Opening Stock
            '            Case 9
            '                Me.mnuUserSettings.Enabled = True                       'Application  Settings
            '            Case 10
            '                Me.mnuHoliday.Enabled = True                            'Add Holiday
            '            Case 11
            '                Me.mnuEmp.Enabled = True                                'Add Employee
            '            Case 12
            '                Me.MnuSetNewUser.Enabled = True                         'Set User & Role  
            '            Case 13
            '                Me.mnuRolesPrivileges.Enabled = True                    'Add Roles & Privileges
            '            Case 14
            '                Me.MnuFirmSetup.Enabled = True                          'Firm Setup
            '            Case 15
            '                Me.MnuFinancialYear.Enabled = True                      'Financial Year
            '            Case 16
            '                Me.MnuFinYrEnding.Enabled = True                        'Financial Year Ending
            '            Case 17
            '                Me.MnuChangePsw.Enabled = True                          'Change Password
            '            Case 18
            '                Me.mnuPayment.Enabled = True                            'Payment Receipt
            '        End Select
            '    Next
            'End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "AssignPrivilege")
        End Try
    End Sub

    Private Sub DisplayData()
        lblFirmName.Text = BCommon.GetFirmName() + " (" + DFinancialYear.GetWorkingFinYear(ConfigurationManager.AppSettings("FirmID")) + ")"
        'lblFirmName.Text = lblFirmName.Text + DFinancialYear.GetWorkingFinYear(ConfigurationManager.AppSettings("FirmID"))
    End Sub

    Private Sub LoadShortCuts()
        Try

            Dim intCount As Integer
            Dim intHSpace As Integer = 1 'Space in two buttons
            Dim intLeft As Integer = 10 + intHSpace
            'Dim intCounter As Integer = 1
            Dim intWidth As Integer
            Dim strCaption As String = ""

            ReDim lblShortCuts(ConfigurationManager.AppSettings("SCCount") - 1)
            intWidth = (pnlShortcuts.Width - 20 - ((lblShortCuts.Length + 1) * intHSpace)) / lblShortCuts.Length
            pnlShortcuts.BackColor = Me.BackColor

            For intCount = 0 To lblShortCuts.Length - 1
                lblShortCuts(intCount) = New Button
                With lblShortCuts(intCount)
                    .Parent = pnlShortcuts
                    'SIZE
                    .Height = pnlShortcuts.Height - 10
                    .Width = intWidth
                    'LOCATION
                    .Left = intLeft
                    .Top = 3
                    ' .FlatStyle = FlatStyle.Popup

                    intLeft = intLeft + intWidth + intHSpace
                    'While Not strCaption <> ""
                    '    intCounter = intCounter + 1
                    '    strCaption = ConfigurationManager.AppSettings("MSC" & intCounter)
                    'End While
                    strCaption = ConfigurationManager.AppSettings("SCK" & intCount + 1) & " : " & ConfigurationManager.AppSettings("SCT" & intCount + 1)
                    .Text = strCaption
                    .TextAlign = ContentAlignment.MiddleCenter
                    .Tag = ConfigurationManager.AppSettings("SCK" & intCount + 1)
                    .Name = intCount + 1

                    'styles
                    .FlatStyle = FlatStyle.Popup
                    .Visible = True

                    AddHandler lblShortCuts(intCount).Click, AddressOf btnShotrtCut_Click
                    strCaption = ""
                End With

            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ShowShortCuts")
        End Try
    End Sub
    Private Sub btnShotrtCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Select Case sender.Tag
            Case "F6"
                LoadForm(frmNgPurchase.Name)
            Case "F7"
                LoadForm(frmSale.Name)
            Case "F8"
                LoadForm(FrmApprovalUpdate.Name)
            Case "F9"
                LoadForm(FrmChallanUpdate.Name)
            Case "F10"
                LoadForm(frmEditChallan.Name)
            Case "F11"
                LoadForm(frmStockTransfer.Name)
            Case ""
                subPriLogOut()
        End Select
    End Sub
    Private Sub subPriLogOut()
        For Each childForm As System.Windows.Forms.Form In MdiChildren
            childForm.Close()
        Next
        SubPriLogin()
    End Sub
    Private Sub SubPriLogin()
        Dim Login As New frmLogin
        Login.strCallFor = "L"


        Login.ShowDialog(Me)
        Login.Dispose()
    End Sub
    Private Function isChildFormExist(ByVal childFormName As String) As Byte
        Try
            If childFormName = "" Then Return 1
            For Each childForm As System.Windows.Forms.Form In MdiChildren
                If childForm.Name = childFormName Then
                    childForm.Activate()
                    Return 1
                End If
            Next
            Return 0

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isChildFormExist")
            Return 0
        End Try
    End Function

    Private Sub LoadForm(ByVal fForm As String)
        Try
            Select Case fForm

                'Case "frmSale"
                '    If isChildFormExist("frmSale") = 0 Then
                '        'If DSale.IsHoliday() > 0 Then
                '        '    BCommon.ShowMsgError(10347)
                '        'Else
                '        Dim frm As New frmSale
                '        Call ShowForm(frm, "T", False)
                '        'End If
                '    End If

                Case "frmSale" 'SALE
                    If isChildFormExist("frmSale") = 0 Then
                        'If DSale.IsHoliday() > 0 Then
                        '    BCommon.ShowMsgError(10347)
                        'Else
                        Dim frm As New frmSale
                        Call ShowForm(frm, "T", False)
                        'End If
                    End If

                Case "frmNgPurchase" 'OLD PURCHASE INVOICE
                    If isChildFormExist("frmNgPurchase") = 0 Then
                        Dim frm As New frmNgPurchase
                        Call ShowForm(frm, "T", False)
                    End If
                Case "frmSaleReturn"
                    If isChildFormExist("frmSaleReturn") = 0 Then
                        Dim frm As New frmSaleReturn
                        Call ShowForm(frm, "T", False)

                    End If
                Case "frmNgPurchase__Return"
                    If isChildFormExist("frmNgPurchase__Return") = 0 Then
                        Dim frm As New frmNgPurchase__Return
                        Call ShowForm(frm, "T", False)

                    End If
                Case "FrmApprovalUpdate"
                    If isChildFormExist("FrmApprovalUpdate") = 0 Then
                        Dim frm As New FrmApprovalUpdate
                        Call ShowForm(frm, "T", False)
                    End If
                Case "FrmChallanUpdate"
                    If isChildFormExist("FrmChallanUpdate") = 0 Then
                        Dim frm As New FrmChallanUpdate
                        Call ShowForm(frm, "T", False)
                    End If
                Case "frmStockTransfer"
                    If isChildFormExist("frmStockTransfer") = 0 Then
                        Dim frm As New frmStockTransfer
                        Call ShowForm(frm, "T", False)
                    End If
                Case "frmEditChallan"
                    If isChildFormExist("frmEditChallan") = 0 Then
                        Dim frm As New frmEditChallan
                        Call ShowForm(frm, "T", False)
                    End If
                    'Case "frmStockTransfer"
                    '    If isChildFormExist("frmStockTransfer") = 0 Then
                    '        Dim frm As New frmStockTransfer
                    '        Call ShowForm(frm, "T", False)
                    '    End If
                Case "FrmStockAdjust"
                    'If isChildFormExist("FrmStockAdjust") = 0 Then
                    '    Dim frm As New FrmStockAdjust
                    '    Call ShowForm(frm, "T", False)
                    'End If
            End Select
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "LoadForm:-" & fForm)
        End Try
    End Sub

    Private Sub ShowForm(ByRef FormObject As Form, ByVal FormType As Char, ByVal ShowAsModal As Boolean)
        '        Dim pt As New Point
        Try
            With FormObject
                If FormType = "M" Then  'MASTER FORMS
                    .StartPosition = FormStartPosition.CenterParent

                ElseIf FormType = "T" Then 'TRANSACTION FORMS                

                    .StartPosition = FormStartPosition.Manual
                    .WindowState = FormWindowState.Normal

                    If Me.MdiChildren.Length <= 0 Then
                        .Top = 1
                        .Left = 0
                        .Height = MdiScaleHeight - 1
                        .Width = MdiScaleWidth
                    Else
                        .Location = Me.MdiChildren(0).Location
                        .Height = Me.MdiChildren(0).Height
                        .Width = Me.MdiChildren(0).Width
                    End If
                End If

                .ShowInTaskbar = False
                If ShowAsModal Then
                    '.MdiParent = Nothing
                    '.Parent = Nothing
                    '.TopLevel = True
                    .StartPosition = FormStartPosition.CenterParent
                    .ShowDialog(Me)
                    .Dispose()
                Else
                    .MdiParent = Nothing
                    .Parent = Nothing
                    .MdiParent = Me
                    .Show()
                End If
                .Activate()
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ShowForm:-" & FormObject.Name)
        End Try
    End Sub

    '@20072012 : Added function for Setting AppSettings values 
    'Private Sub PharmacyStartup()
    '    Exit Sub
    '    Dim dtGetControls As New DataTable
    '    ''im dtbMODE As New DataTable
    '    Dim count As Integer
    '    ''Dim dtbFinyrid As DataTable
    '    Dim strMsg As String = String.Empty
    '    Dim dtbFinYr As New DataTable
    '    Dim WrkFinYr As Integer
    '    Try
    '        ' Add code for Set Form Mode value
    '        '<<start
    '        'GETTING Working FINACIAL YEAR FROM DATABASE AND SET IN CONFIG 
    '        WrkFinYr = DFinancialYear.GetWorkingFinyearID(ConfigurationManager.AppSettings("FirmID"))
    '        ConfigurationManager.AppSettings.Set("FinYrId", WrkFinYr)


    '        dtbFinYr = DFinancialYear.GetActiveFinyear(ConfigurationManager.AppSettings("FirmID"))
    '        'Check whether the Current date is Previous than Active Financial Year Start Date
    '        If Now.Date < dtbFinYr.Rows(0).Item("Fin_start_dt").date Then
    '            strMsg = BCommon.GetMessage(10366)
    '            strMsg = Replace(strMsg, "@STARTDATE", dtbFinYr.Rows(0).Item(0).date)
    '            strMsg = Replace(strMsg, "@ENDDATE", dtbFinYr.Rows(0).Item(1).date)
    '            BCommon.ShowMessage(strMsg)
    '            Me.Close()
    '            'Check whether the Current date Large than Active Financial Year End Date
    '        Else
    '            If WrkFinYr = dtbFinYr.Rows(0).Item("FinYrId") Then
    '                ConfigurationManager.AppSettings.Set("FormMode", "A")
    '                If Date.Today > dtbFinYr.Rows(0).Item("Fin_end_dt") Then
    '                    If BCommon.ShowMsgError(10407, "YN") = Windows.Forms.DialogResult.No Then
    '                        Global.System.Windows.Forms.Application.Exit()
    '                    Else
    '                        Dim frm As New frmSetFinancialYear
    '                        Call ShowForm(frm, "M", True)
    '                        If boolFinYr = True Then Global.System.Windows.Forms.Application.Exit()
    '                    End If
    '                End If
    '            Else 'ACTIVE AND WORKING FIN YR NOT SAME 
    '                ConfigurationManager.AppSettings.Set("FormMode", "R")
    '                MnuFinYrEnding.Enabled = False
    '            End If
    '        End If

    '        ' ''dtbMODE = BCommon.CheckFormMode()
    '        ' ''    If dtbMODE.Rows.Count > 0 Then
    '        ' ''        If dtbMODE.Rows(0).Item("Status").ToString = "A" AndAlso dtbMODE.Rows(0).Item("Working_Status").ToString = "A" Then
    '        ' ''            ConfigurationManager.AppSettings.Set("FormMode", "A")
    '        ' ''        Else
    '        ' ''            ConfigurationManager.AppSettings.Set("FormMode", "R")
    '        ' ''            MnuFinYrEnding.Enabled = False
    '        ' ''            'mnuRolesPrivileges.Enabled = False
    '        ' ''            'MnuSetNewUser.Enabled = False
    '        ' ''            'MnuChangePsw.Enabled = False
    '        ' ''            'MnuFirmSetup.Enabled = False
    '        ' ''            'mnuUserSettings.Enabled = False
    '        ' ''            'MnuRestoreDb.Enabled = False
    '        ' ''            'MnuCounterSettings.Enabled = False                    
    '        ' ''        End If
    '        ' ''    End If
    '        '>>end
    '        ''dtbFinyrid = DFinancialYear.GetFinyears(ConfigurationManager.AppSettings("FinYrId"))
    '        ''With dtbFinyrid
    '        ''    If .Rows.Count > 0 Then
    '        ''        If (Now.Date > .Rows(0).Item("Fin_end_dt").date OrElse Now.Date < .Rows(0).Item("Fin_start_dt").date) Then
    '        ''            strMsg = BCommon.GetMessage(10366)
    '        ''            strMsg = Replace(strMsg, "@STARTDATE", .Rows(0).Item(0).date)
    '        ''            strMsg = Replace(strMsg, "@ENDDATE", .Rows(0).Item(1).date)
    '        ''            BCommon.ShowMessage(strMsg)
    '        ''            Me.Close()
    '        ''        End If
    '        ''    End If
    '        ''End With
    '        dtGetControls = BTab.GetControls()
    '        If dtGetControls.Rows.Count > 0 Then
    '            For count = 0 To dtGetControls.Rows.Count - 1
    '                If Trim(dtGetControls.Rows(count).Item("KeyName")) <> Nothing Or Trim(dtGetControls.Rows(count).Item("KeyName")) <> "" Then
    '                    ConfigurationManager.AppSettings.Set(dtGetControls.Rows(count).Item("KeyName"), dtGetControls.Rows(count).Item("PrefValue"))
    '                End If
    '            Next
    '        End If
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "PharmacyStartup")
    '    End Try
    'End Sub
#End Region

#Region "Standard Menu Click"
    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            ''Dim FileName As String = SaveFileDialog.FileName
            ' TODO: Add code here to save the current contents of the form to a file.
        End If
    End Sub

    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Global.System.Windows.Forms.Application.Exit()
    End Sub

#End Region

#Region "TRANSACTION MENU CLICK"
  
    Private Sub mnuPurchaseInvoice_Click(ByVal sender As Object, ByVal e As EventArgs) Handles mnuPurchaseInvoice.Click
        LoadForm("frmNgPurchase")
    End Sub

    Private Sub SaleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSale.Click
        'ShortCut_Click("SALE")
        LoadForm("frmSale")
    End Sub

  
    Private Sub mnuPurchaseReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPurchaseReturn.Click
        LoadForm(frmNgPurchase__Return.Name)
    End Sub

    Private Sub mnuSaleReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaleReturn.Click
        LoadForm("frmSaleReturn")
    End Sub
#End Region

#Region "SEARCH"

    Private Sub mnuSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSearch.Click
        LoadForm("frmMasterBrowse")
    End Sub

#End Region

#Region "Menu_Reports_Click"

    Private Sub mnuStock_VendorWise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStock_VendorWise.Click
        '1         'FromDate
        '          'ToDate
        '          'Profit In A/P
        Call ShowReport("VendorWiseStock", True)
    End Sub
    Private Sub mnuStock_CompanyWise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStock_CompanyWise.Click
        '2         'FromDate
        '          'ToDate
        '          'Profit In A/P
        Call ShowReport("CompanyWiseStock", True)
    End Sub
    Private Sub mnuStock_ShelfWise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStock_ShelfWise.Click
        '3         'FromDate
        '          'ToDate
        '          'Profit In A/P
        Call ShowReport("ShelfWiseStock", True)
    End Sub

    Private Sub mnuStock_NearExpiry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStock_NearExpiry.Click
        '4   
        Call ShowReport("ItemsNearToExpiry")
    End Sub

    Private Sub mnuStock_Expired_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStock_Expired.Click
        '5
        Call ShowReport("ExpiredStock")
    End Sub

    Private Sub mnuVouchers_PurInvoice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_PurInvoice.Click
        '6   InvoiceID
        Call ShowReport("PurchaseInvoices", True)
    End Sub

    Private Sub mnuVouchers_Sale_Bill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_Sale_Bill.Click
        '9  'SaleID
        Call ShowReport("SaleBill", True)
    End Sub

    Private Sub mnuVouchers_Sale_CounterSale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_Sale_CounterSale.Click
        '10        FromDate
        '          'ToDate
        '          'Profit In A/P'CounterSale.rpt
        Call ShowReport("CounterSale", True)
    End Sub

    Private Sub mnuVouchers_Sale_Vendorwise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_Sale_Vendorwise.Click
        '11   'VendorWiseSale.rpt
        '         'FromDate
        '          'ToDate
        '          'Profit In A/P
        Call ShowReport("VendorWiseSale", True)
    End Sub

    Private Sub mnuVouchers_Sale_Itemwise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_Sale_Itemwise.Click
        '12 ItemWiseSale.rpt
        '         'FromDate
        '          'ToDate
        '          'Profit In A/P
        Call ShowReport("ItemWiseSale", True)
    End Sub

    Private Sub mnuVouchers_Sale_Datewise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_Sale_Datewise.Click
        '13   'DateWiseSale.rpt
        '         'FromDate
        '          'ToDate
        '          'Profit In A/P
        Call ShowReport("DateWiseSale", True)
    End Sub
    Private Sub mnuVouchers_PurchaseReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_PurchaseReturn.Click
        '14  'PurchaseReturn.rpt
        'PurReturnID
        Call ShowReport("PurchaseReturn", True)
    End Sub

    Private Sub mnuVouchers_SaleReturn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_SaleReturn.Click
        '15 'SaleReturn.rpt
        'ReturnID
        Call ShowReport("SaleReturn", True)
    End Sub

    Private Sub mnuPayments_Reciepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPayments_Reciepts.Click
        '16 PaymentReceipt.rpt
        'PayID
        Call ShowReport("PaymentReceipt", True)
    End Sub

    Private Sub mnuPayments_Vendor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPayments_Vendor.Click
        '17VendorPayment.rpt
        Call ShowReport("VendorPayment", True)
    End Sub

    Private Sub mnuPayments_Pending_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPayments_Pending.Click
        '18 'PendingPayments.rpt
        'Vendor
        Call ShowReport("PendingPayments", True)
    End Sub

    Private Sub mnuPayments_OutStanding_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPayments_OutStanding.Click
        '19 'OutStandingPayments.rpt
        Call ShowReport("OutStandingPayments", False)
    End Sub
    Private Sub mnuRegisters_Sale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRegisters_Sale.Click
        '20 'SaleRegister.rpt
        Call ShowReport("SaleRegister", True)
    End Sub

    Private Sub mnuRegisters_Purchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRegisters_Purchase.Click
        '21 'PurchaseRegister.rpt
        Call ShowReport("PurchaseRegister", True)
    End Sub
    Private Sub mnuVouchers_DC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_DC.Click
        '7        
    End Sub

    Private Sub mnuVouchers_DcToPI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVouchers_DcToPI.Click
        '8
    End Sub
    Private Sub ShowReport(ByVal ReportName As String, Optional ByVal Parameters As Boolean = False)
        'Dim Report As New frmReport
        'Dim ReportPreview As New Reports.frmReportViewer
        'Dim ReportView As New frmReportPreview
        'Try
        '    If Parameters = True Then
        '        Select Case ReportName
        '            Case "DateWiseSale", "PurchaseRegister", "SaleRegister", "PendingPayments", "VendorWiseStock", "VendorPayment", "CompanyWiseStock", "ShelfWiseStock"
        '                Report.ReportName = ReportName
        '                Report.ShowDialog()
        '            Case Else
        '                ReportView.ReportName = ReportName
        '                ReportView.ShowDialog()
        '        End Select
        '    Else
        '        ReportPreview.ReportName = ReportName
        '        ReportPreview.Text = BCommon.GetReportHeading(ReportName)
        '        ReportPreview.ShowDialog()
        '    End If

        'Catch ex As Exception
        '    BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ShowReport")
        'End Try
    End Sub


#End Region
    Private Sub ContentsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContentsToolStripMenuItem.Click
        'Try
        '    'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.TableOfContents, "")
        'Catch ex As Exception
        '    BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ContentsToolStripMenuItem_Click")
        'End Try
    End Sub

    Private Sub MDIPharmacy_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        Try
            'If e.KeyCode = Keys.F1 Then
            '    e.SuppressKeyPress = True
            '    'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Multiple Document Interface")
            'End If

            If e.Control = True Then
                If e.KeyCode = Keys.E Then
                    Dim eodForm As Frm_EOD = New Frm_EOD()
                    eodForm.ShowDialog(Me)
                End If
                Exit Sub
            End If

            If e.Shift = True Then Exit Sub
            'keys.F1.KeyAscii = 112    
            If e.KeyCode - 111 > 11 Or e.KeyCode - 111 <= 0 Then Exit Sub '   '---------Check hotkeys -------------
            Dim strCaption As String
            strCaption = Trim(ConfigurationManager.AppSettings("MSC" & e.KeyCode - 111))
            ' If strCaption <> "" Then Call ShortCut_Click(strCaption)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "MDIPharmacy_KeyUp")
        End Try
    End Sub

    Private Sub MDIPharmacy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim objsplash As New frmSplash

        Dim dtFirm As New DataTable
        Dim strvar As String = String.Empty
        Try
            Me.AutoScroll = False  'Chandrakant
            SetMDISchaleValues()
            SetPanelHeading()
            strvar = strvar & " " & My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Build
            ConfigurationManager.AppSettings.Set("MsgTitle", My.Application.Info.Title & " " & strvar)

            'frmSplash.ShowDialog()
            ptStartPoint = New Point(Me.Left + 2, pnlHeading.Height + 1) 'MenuStrip.Height +

            SubPriLogin()
            'Call DeleteStockItems()
            'Call ShowForm()
            
            'If Login.MDIClose Then
            '    End
            'End If

            Call DisplayData()
            ' Call ExpiredItems()      ' 28/11/2007
            'Call AssignPrivilege()   '@20/03/2008 : Added regarding assignment of Roles & Privilege

            LoadShortCuts()

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "MDIPharmacy_Load")
        End Try
    End Sub
    Private Sub ExitToolStripMenuItem1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem1.Click
        If BCommon.ShowMsgError(10240, "YN") = Windows.Forms.DialogResult.Yes Then
            'If MessageBox.Show(BCommon.GetMessage(10240), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Me.Close()
            End
        End If
    End Sub
    Private Sub tmrClock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrClock.Tick
        '        lblDateTime.Text = TimeOfDay
        lblScreen.Text = FormatDateTime(Now, DateFormat.LongDate)
    End Sub


    Private Sub mnuWinCascade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuWinCascade.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub mnuWinVertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuWinVertical.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub mnuWinHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuWinHorizontal.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ReporToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReporToolStripMenuItem.Click
        LoadForm("frmReports")
    End Sub

    Private Sub MnuFinancialYear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        LoadForm("frmFinancialYear")
    End Sub

    Private Sub MnuFinYrEnding_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        LoadForm("frmSetFinancialYear")
    End Sub

    Private Sub MasterToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        LoadForm("MasterImport")
    End Sub
    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs)
        If MessageBox.Show("Do you want to exit application", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then
            End
        End If
    End Sub

    Private Sub ApprovalUpdateToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ApprovalUpdateToolStripMenuItem.Click
        LoadForm("FrmApprovalUpdate")

    End Sub
    
    Private Sub ChallanUpdateToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ChallanUpdateToolStripMenuItem.Click
        LoadForm("FrmChallanUpdate")
    End Sub

    Private Sub STOCKTRNASFERToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles STOCKTRNASFERToolStripMenuItem.Click
        LoadForm("frmStockTransfer")
    End Sub

    Private Sub CHALLANEDITToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CHALLANEDITToolStripMenuItem.Click
        LoadForm("frmEditChallan")
    End Sub

    Private Sub STOCKADJUSTMENTToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles STOCKADJUSTMENTToolStripMenuItem.Click
        LoadForm("FrmStockAdjust")

    End Sub

    
End Class
